<?php

namespace App\Http\Controllers\Common;

use App\Http\Controllers\Controller;
use App\Services\UploadService;
use Illuminate\Http\Request;

class UploadController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware('front');
    }

    public function make(Request $request, UploadService $uploadService)
    {
        $info = $uploadService->upload($request->file);
        //转为https协议
        $https = preg_replace('/https?/i', 'https', site()['domain']);

        $info['path'] = $https . '/' . trim($info['path'], '/');
        //根据站点域名将附件文件路径构建成绝对路径，好处，微信服务器可以访问图片，坏处，更换域名后，需要修稿mysql记录的文件路径。

        return $info;
    }
}
